﻿Imports System.Data.Linq
Imports System.Linq
Public Class CRoleMenuController
    Dim objDataContext As New TanNamChinhDataContext
    Public Function InsertRecord(ByVal LocalTable As tblRoleMenu) As Integer
        Try
            objDataContext.tblRoleMenus.InsertOnSubmit(LocalTable)
            objDataContext.SubmitChanges()
            Return LocalTable.ID_RoleMenu
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Sub DeleteAllByRole(ByVal _idRole As Integer)
        Try
            objDataContext.tblRoleMenus.DeleteAllOnSubmit(From r In objDataContext.tblRoleMenus Where r.ID_Role = _idRole Select r)
            objDataContext.SubmitChanges()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Function CheckMenuInRole(ByVal idRole As Integer, ByVal idMenu As Integer) As Boolean
        'cach 1
        Return objDataContext.tblRoleMenus.Any(Function(m) m.ID_Menu = idMenu And m.ID_Role = idRole)
    End Function
    Public Function CheckMenuInRoleByName(ByVal idRole As Integer, ByVal menuText As String) As Boolean
        'cach 1
        Return objDataContext.tblRoleMenus.Any(Function(m) m.tblMenu.MenuText = menuText And m.ID_Role = idRole)
    End Function
    Public Sub New()
        objDataContext = New TanNamChinhDataContext
    End Sub
    Public Sub New(ByVal _obj As TanNamChinhDataContext)
        objDataContext = _obj
    End Sub
End Class
